/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { resolveHookDependency } from '../../../utils/task-util.js';
import { GenerateLoaderJson } from '../../generate-loader-json.js';
import { LegacyHookCompileResource } from '../../legacy-tasks/hook/legacy-hook-compile-resource.js';
import { LegacyGenerateJsManifest } from '../../legacy-tasks/legacy-generate-js-manifest.js';
import { LegacyGenerateLoaderJson } from '../../legacy-tasks/legacy-generate-loader-json.js';
import { PreCheckSyscap } from '../../pre-check-syscap.js';
import { ReplacePreviewerPage } from '../../previewer/replace-previewer-page.js';
import { ModuleTaskService } from '../../service/module-task-service.js';
import { TargetTaskService } from '../../service/target-task-service.js';

import { AbstractPreviewerRes } from './abstract-previewer-res.js';

/**
 * for previewer hook only in hap module
 *
 * @2022/8/11
 */
export class BuildPreviewerRes extends AbstractPreviewerRes {
  constructor(moduleTaskService: ModuleTaskService, isFaMode: boolean) {
    super(moduleTaskService, isFaMode);
  }

  initTaskDepends(taskTargetService: TargetTaskService) {
    if (this._isFaMode) {
      this.dependsOn(resolveHookDependency(LegacyGenerateLoaderJson.name, taskTargetService.getTargetData().getTargetName()));
      this.dependsOn(resolveHookDependency(LegacyGenerateJsManifest.name, taskTargetService.getTargetData().getTargetName()));
      this.dependsOn(resolveHookDependency(LegacyHookCompileResource.name, taskTargetService.getTargetData().getTargetName()));
    } else {
      this.dependsOn(resolveHookDependency(GenerateLoaderJson.name, taskTargetService.getTargetData().getTargetName()));
      this.dependsOn(resolveHookDependency(ReplacePreviewerPage.name, taskTargetService.getTargetData().getTargetName()));
    }

    this.dependsOn(resolveHookDependency(PreCheckSyscap.name, taskTargetService.getTargetData().getTargetName()));
  }
}
